package be.vdab.dao;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.ConcurrentHashMap;

import be.vdab.entities.Saus;

public class SausenDAO {
	static private Map<Long, Saus> sausen = new ConcurrentHashMap<Long, Saus>();
	static {
		sausen.put(20L,new Saus(20L, "cocktail", "ketchup", "whiskey", "mayonaise"));
		sausen.put(21L,new Saus(21L, "mayonaise", "ei", "melk"));
		sausen.put(22L,new Saus(22L, "mosterd", "mayonaise", "mosterdzaadjes"));
		sausen.put(23L,new Saus(23L, "tartaar", "tartaar", "ajuin"));
		sausen.put(24L,new Saus(24L, "vinaigrette", "olie", "meerOlie"));
	}
	
	public String getRandomSausNaam() {
		Random generator = new Random();
		int randomIndex = generator.nextInt(sausen.size());
		ArrayList<Saus> sausenArray = new ArrayList<Saus>(sausen.values());
		Saus saus = sausenArray.get(randomIndex);
		String sausNaam = saus.getNaam();
		return sausNaam;
	}
	
	public Iterable<Saus> findAll() {
		return new ArrayList<Saus>(sausen.values());
	}
	
	public Iterable<Saus> findIngedrient(String ingredient) {
		List<Saus> resultaat = new ArrayList<Saus>();
		for (Saus saus : sausen.values()) {
			String[] ingedrienten = saus.getIngedrienten();
			for (int i=0; i<ingedrienten.length;i++) {
				 if (ingedrienten[i].compareTo(ingredient)==0) 
					resultaat.add(saus);		
			}
		}
			return resultaat;
		}
	public void removeSaus(Long saus) {
		sausen.remove(saus);
	}
	}
	

